package utilstest;

import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.Calendar;
import java.util.Date;

import static java.util.Calendar.DATE;
import static java.util.Calendar.MONTH;

public class UtilsTest {
    public static void main(String[] args) {
//        mathTest();
//        calendarTest();
        newDatePackageTest();
    }

    public static void mathTest(){
        System.out.println("-->"+Math.sqrt(4));
        System.out.println("-->"+Math.cbrt(27));
        System.out.println("-->"+Math.exp(2));
        System.out.println("-->"+Math.pow(3,2));
        System.out.println("-->"+Math.log(Math.E));
        System.out.println("-->"+Math.log10(100));
        System.out.println("-->"+Math.copySign(-1.2,1));
        System.out.println("-->"+Math.signum(-1.2));
        System.out.println("-->"+Math.nextAfter(1.2,1000.0));
        System.out.println("-->"+Math.nextUp(1.5));
        System.out.println("-->"+Math.random());
    }

    public static void calendarTest(){
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        date = calendar.getTime();
        calendar.setTime(date);
        System.out.println(calendar.getTime());
        calendar.set(MONTH,13);
        System.out.println(calendar.getTime());
//        calendar.setLenient(false); //关闭容错性，则下面打印会抛出异常
        calendar.set(MONTH,13);
        System.out.println(calendar.getTime());

        calendar.set(2003,7,31);
        calendar.set(MONTH,8);
//        System.out.println(calendar.getTime());
        calendar.set(DATE,5);
        System.out.println(calendar.getTime());
    }

    public static void newDatePackageTest(){
        Clock clock = Clock.systemUTC();
        System.out.println(""+clock.instant());
        System.out.println(clock.millis()==System.currentTimeMillis());

        Duration d = Duration.ofSeconds(6000);
        System.out.println(d.toMillis());
        System.out.println(d.toHours());
        System.out.println(d.toDays());
        Clock clock1 = Clock.offset(clock,d);
        System.out.println(clock1.instant());

        Instant instant = Instant.now();
        System.out.println(instant);
    }
}
